package com.ase.leetcode;

/**
 * @author gyhstart
 * @create 2021/3/14 - 14:30
 **/
public class Two {
    public static void main(String[] args) {
        String word = "internationalization";
        String abbr = "i12iz4n1";
        System.out.println("valid(word,abbr) = " + valid(word, abbr));
    }

    public static boolean valid(String word, String abbr) {
        char[] chars = abbr.toCharArray();
        int num = 0;
        int next = 0;
        for (char c : chars) {
            if (c >= '0' && c <= '9') {
                if (num == 0 && c == '0') {
                    return false;
                }
                num = num * 10 + (c - '0');
                continue;
            }

            next = next + num;
            if (next >= word.length() || (word.charAt(next) != c)) {
                return false;
            }
            next++;
            num = 0;
        }
        return next + num == word.length();
    }
}

